﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Web;
using System.Web.Security;
using System.Web.Profile;

namespace MvcCarConsume.Domain
{
    public class SqlAccountService : IAccountService
    {
        public bool AuthenticationUser(string UserName, string Password)
        {
            return Membership.ValidateUser(UserName, Password);
        }

        public void LogIn(string UserName, bool remember)
        {
            FormsAuthentication.SetAuthCookie(UserName, remember);
        }

        public string GetRedirectUrl(string UserName, bool remember)
        {
            //!! if querystring and form are both not contain ReturnUrl , this may probably happen using ajax post
            // the FormsAuthentication.GetRedirectUrl will return FormsAuthentication.DefaultUrl
            string url = FormsAuthentication.GetRedirectUrl(UserName, remember);
            if (url == FormsAuthentication.DefaultUrl)
                return null;
            return url;
        }

        public void LogOut()
        {
            FormsAuthentication.SignOut();
        }

        public MembershipUser CreateUser(
            string username,
            string password,
            string email,
            string passwordQuestion,
            string passwordAnswer,
            bool isApproved,
            Object providerUserKey,
            out MembershipCreateStatus status
        )
        {
            return Membership.CreateUser(username,
             password,
             email,
             passwordQuestion,
             passwordAnswer,
             isApproved,
             providerUserKey,
            out  status);
        }
        public MembershipUser CreateUser(
            string username,
            string password,
            string email,
            out MembershipCreateStatus status
         )
        {

            return this.CreateUser(username, password, email, null, null, true, null, out status);
        }

    }
}
